package com.xuzz.study.springboot.starter;

import com.xuzz.study.springboot.DemoProperties;
import com.xuzz.study.springboot.DemoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@EnableConfigurationProperties(DemoProperties.class)
@ConditionalOnProperty(
        prefix = "demo",
        name = "isopen",
        havingValue = "true"
)
public class DemoAutoConfiguration {
    @Autowired
    DemoProperties demoProperties;

    @Bean(name="demoService")
    public DemoService demoService()
    {
        return new DemoService(demoProperties.getSayWhat(),demoProperties.getToWho());
    }
}
